package net.oschina.app.adapter.my;

import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.Spanned;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import net.oschina.app.R;
import net.oschina.app.adapter.BaseRecyclerViewAdapter;
import net.oschina.app.bean.Active;
import net.oschina.app.databinding.MsgItemDiscussBinding;
import net.oschina.app.util.EmoParser;
import net.oschina.app.util.UIUtils;

import java.util.List;

/**
 * Created by YL on 2017/4/5.
 */
public class ActiveDiscussAdapter extends BaseRecyclerViewAdapter {
    /**
     * Created by YL on 2017/4/2.
     */
    private List<Active> flist;
    private TextView mExpText;
    private ImageView mImg;

    public ActiveDiscussAdapter(List<Active> active) {
        this.flist = active;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = mInflater.inflate(R.layout.msg_item_discuss, parent, false);
        ActiveViewHolder holder = new ActiveViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        Active active = flist.get(position);
        MsgItemDiscussBinding binding = DataBindingUtil.bind(holder.itemView);
        binding.setActiveDiscuss(active);
        //html文本
        Spanned spanned = Html.fromHtml(active.getMessage());
        binding.setMessage(EmoParser.parserEmo(UIUtils.getContext(), spanned.toString()));
        binding.setObjecttype(active.getObjectType() + "");
        //图片
        binding.setImageUrl(active.getPortrait());
        binding.setObjectNameBody( Html.fromHtml(EmoParser.richText(active.getObjectReply().getObjectName(), active.getObjectReply().getObjectBody())));
    }

    @Override
    public int getItemCount() {
        return flist.size();
    }

    public class ActiveViewHolder extends RecyclerView.ViewHolder {

        public ActiveViewHolder(View itemView) {
            super(itemView);
        }
    }
}
